/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isd.promocion.web;



import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import com.isd.promocion.modelo.Promocion;
import com.isd.promocion.rn.PromocionRN;

/**
 *
 * @author ctrosch
 */
@ManagedBean (name="conversoresPromocion")
@SessionScoped
public class ConversoresPromocion {
    
    @EJB private PromocionRN promocionRN;

    /** Creates a new instance of ConversoresBean */
    public ConversoresPromocion() {
        
    }
    
    public Converter getPromocion() {
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if (value.trim().equals("") || value == null) {
                    return null;
                }

                return promocionRN.getPromocion(Integer.parseInt(value));
            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                if (value == null || value.equals("")) {
                    return "";
                } else {

                    return ((Promocion) value).getNroPromocion()+ "";
                }
            }
        };
    }   
    
   
}
